import React, { Component } from 'react';
import { Form,Input,Select } from 'antd';
import PropTypes from 'prop-types';
import './modal.css';

const { Option } = Select;

class AddProjectForm extends Component {

  static propTypes = {
    setForm: PropTypes.func.isRequired,
  }

  formRef = React.createRef();  // form对象
  
  componentDidMount() {
    this.props.setForm(this.formRef);  // 调用父组件传递的函数，目的是将 参数以实参的形式传递给父组件
    //console.log('form',this.formRef);
  }

  render() {
    const layout = {
      labelCol: { span: 6 },
      wrapperCol: { span: 16 },
    };
    return (
      <div>
        <Form 
          {...layout} 
          ref={this.formRef}   
          name="control-ref" 
          onFinish={this.onFinish}
          initialValues={{
            pro_look_range: "公开：所有成员都可以看见此项目",
          }}
        >    
          <Form.Item 
            name="pro_id" 
            label="项目编号" 
            rules={[{ required: true }]}
          >
            <Input placeholder="请输入项目编号"/>
          </Form.Item>

          <Form.Item 
            name="pro_name" 
            label="项目名称" 
            rules={[{ required: true }]}
          >
            <Input placeholder="请输入项目名称"/>
          </Form.Item>

          <Form.Item 
            name="pro_look_range" 
            label="可见范围" 
            rules={[{ required: true }]}
          >
            <Select
              onChange={this.onGenderChange}
              allowClear
            >
              <Option value="1">公开：所有成员都可以看见此项目</Option>
              <Option value="2">私有：只有加入项目的成员可查看</Option>
            </Select>
          </Form.Item>

          <Form.Item 
            name="pro_type" 
            label="所属分组" 
            rules={[{ required: true }]}
          >
            <Select
              onChange={this.onGenderChange}
              allowClear
              placeholder="请选择所属分组"
            >
              <Option value="分组1">分组1</Option>
              <Option value="分组2">分组2</Option>
              <Option value="分组3">分组3</Option>
            </Select>
          </Form.Item>

          <Form.Item name="pro_remark" label="描述">
            <Input.TextArea />
          </Form.Item>
        </Form>
      </div>
      
    )
  }
}

export default AddProjectForm;